import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TaskProcessPanel } from "../../task/imgtxt/TaskProcessPanel";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { GameProxy } from "../../../mvc/GameProxy";
import { TaskInfo } from "../../../model/TaskInfo";
type int = number;
//class LGXBTaskItem
    
    export  class LGXBTaskItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            buttonMode = true;
            return;
        }

        /* internal  */initUI(): void
        {
            this._titleTxt = ObjCreate.createTextField("", 0, 0, -1, -1, null, GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1));
            this._titleTxt.textColor = GlobalStyle.color1Uint;
            this._titleTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._titleTxt.selectable = false;
            this._titleTxt.width = 360;
            this._titleTxt.height = 20;
            this._titleTxt.y = 5;
            addChild(this._titleTxt);
            this._txtStatus = new Object /* flash.text.TextField */();
            this._txtStatus.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._txtStatus.selectable = false;
            this._txtStatus.width = 360;
            this._txtStatus.height = 20;
            this._txtStatus.y = 28;
            addChild(this._txtStatus);
            this._taskProcessPanel = new TaskProcessPanel();
            addChild(this._taskProcessPanel);
            this._quickComBtn = new GButton();
            this._quickComBtn.styleName = "Button";
            this._quickComBtn.setSize(70, 22);
            this._quickComBtn.y = 365;
            this._quickComBtn.x = 8;
            this._quickComBtn.label = Language.getString(20655);
            this._quickComBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._quickComBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onQuickComClickHandler);
            addChild(this._quickComBtn);
            this._btnGiveup = new GButton();
            this._btnGiveup.styleName = "Button";
            this._btnGiveup.setSize(70, 22);
            this._btnGiveup.y = 365;
            this._btnGiveup.x = 88;
            this._btnGiveup.label = Language.getString(20235);
            this._btnGiveup.textField.filters = [FilterConst.nameGlowFilter];
            this._btnGiveup.addEventListener(flash.events.MouseEvent.CLICK, this.onGiveupHandler);
            addChild(this._btnGiveup);
            return;
        }

        public updateBtnLabel(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._quickComBtn.label = Language.getString(20655);
                this._btnGiveup.enabled = true;
            }
            else 
            {
                this._btnGiveup.enabled = false;
                this._quickComBtn.label = Language.getString(20424);
            }
            return;
        }

        /* internal  */onQuickComClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._quickComBtn.label != Language.getString(20424)) 
            {
                this.hasClickQuickBtn = true;
                this.quickCompleteHander();
            }
            else 
            {
                this.hasClickQuickBtn = false;
                this.clickGetBonusHandler();
            }
            return;
        }

        public quickCompleteHander(): Boolean
        {
            if (this._taskInfo == null) 
            {
                return false;
            }
            var loc1=this.checkEnabledQuickComplete(3000);
            if (loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskQuickComReq, this._taskInfo));
            }
            else 
            {
                this.hasClickQuickBtn = false;
                Dispatcher.dispatchEvent(new Object /* flash.events.Event */("#CoinIsNotEnough#", true));
            }
            return loc1;
        }

        /* internal  */checkEnabledQuickComplete(arg1: int): Boolean
        {
            var loc1=Cache.instance.role.money;
            var loc2=loc1.coin + loc1.coinBind;
            if (loc2 < arg1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(20681));
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, arg1));
                return false;
            }
            return true;
        }

        public clickGetBonusHandler(): void
        {
            if (this._taskInfo == null) 
            {
                return;
            }
            GameProxy.taskProxy.endTaskReq(this._taskInfo.sTask.endNpc, this._taskInfo.sTask.code);
            return;
        }

        /* internal  */onGiveupHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskCancelTask, this._taskInfo));
            return;
        }

        public updateData(arg1: TaskInfo): void
        {
            this._taskInfo = arg1;
            this._titleTxt.htmlText = arg1.processStr;
            this._txtStatus.htmlText = arg1.isCompleted;
            this._taskProcessPanel.updateData(this._titleTxt, this._taskInfo);
            return;
        }

        public dispose(): void
        {
            this._taskInfo = null;
            this._taskProcessPanel.dispose();
            return;
        }

        public /* override */ get width(): number
        {
            return 360;
        }

        public /* override */ get height(): number
        {
            return 20;
        }

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_txtStatus: Object /* flash.text.TextField */;

        /* internal */ /* var */_taskInfo: TaskInfo;

        /* internal */ /* var */_taskProcessPanel: TaskProcessPanel;

        /* internal */ /* var */_quickComBtn: GButton;

        /* internal */ /* var */_btnGiveup: GButton;

        public /* var */hasClickQuickBtn: Boolean=false;
    }
